<template>
  <div>
    <router-link
      tag="div"
      to="/"
      v-show="!showHeader"
      class="back iconfont">&#xe624;
    </router-link>
    <div class="header" v-show="showHeader" :style="opacityStyle">
      <router-link
        tag="div"
        to="/"
        class="header-left">
        <div class="iconfont">&#xe624;</div>
      </router-link>
      <div class="header-center">故宫</div>
    </div>
  </div>
</template>
<script type='text/babel'>
export default {
  data () {
    return {
      showHeader: false,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  created () {},
  mounted () {},
  updated () {},
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  },
  methods: {
    handleScroll () {
      let scrollTop
      scrollTop = document.documentElement.scrollTop
      if (scrollTop > 48) {
        let opacity
        opacity = scrollTop / 150
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showHeader = true
      } else {
        this.showHeader = false
      }
    }
  },
  computed: {},
  watch: {}
}
</script>
<style scoped lang="scss" rel="stylesheet/scss">
  @import "../../../assets/styles/reset.css";
  @import "../../../assets/styles/variable";
  .back{
    position: fixed;
    top:10px;
    left:10px;
    z-index: 10;
    width:38px;
    height:38px;
    border-radius: 50%;
    text-align: center;
    line-height:38px;
    color: #fff;
    background: rgba(0,0,0,0.5);
  }
  .header{
    position: fixed;
    top:0;
    left:0;
    right:0;
    z-index: 5;
    height:44px;
    line-height: 44px;
    background: $bgColor1;
    @include displayFlex();
    .header-left{
      height:44px;
      padding:0 10px;
      line-height: 44px;
      .iconfont{
        color: #fff;
      }
    }
    .header-center{
      @include flex(1);
      padding-right: 44px;
      color: #fff;
      text-align: center;
    }
  }
</style>
